#ifndef _np_renderer
#define _np_renderer

#include "Singleton.h"

#include <Vec3.h>
#include <Color.h>
#include "RObject.h"

#include <sg/sg.h>

class Renderer: public virtual Singleton<Renderer>{
protected:
	//float mmvpMatrix[16];
	//float mmMatrix[16];
	//float mvMatrix[16];
	sgMat4 mmvpMatrix;
	sgMat4 mmMatrix;

	//camera values
	sgVec3 mEyePos;
	sgVec3 mEyeAt;
	sgVec3 mEyeUp;

	sgMat4 mvMatrix;
	sgFrustum mpMatrix;

	static const GLuint MAX_VERTICES;
	shared_ptr<Material> debug_mat;
	RObject* lineList;
	RObject* triList;

	inline void copy_to(const Vec3& v, float* p, const int& index){
		p[index] = v.x;
		p[index+1] = v.y;
		p[index+2] = v.z;
	};
	inline void copy_to(const Color& v, float* p, const int& index){
		p[index] = v.r;
		p[index+1] = v.g;
		p[index+2] = v.b;
		p[index+3] = v.a;
	};

public:
	Renderer();
	virtual ~Renderer();
	void render(const float& elapsed);
	void render_line(const Vec3& p0, const Vec3& p1, const Color& color);
	void render_triangle(const Vec3& p0, const Vec3& p1, const Vec3& p2, const Color& color);

	void resource_reset(const int& width, const int& height);

	inline const GLfloat* get_mvp_matrix(){
		return reinterpret_cast<GLfloat*>(mmvpMatrix);
	};
};

#endif //#ifndef _np_renderer
